import {useEffect, useState} from 'react';
import ProForm, {ProFormRadio, ProFormSelect, ProFormText} from "@ant-design/pro-form";
import {Form, Input, Modal} from 'antd';
import {getExpress} from "@/services/ant-design-pro/order";

const SendGoodsModal = (props: any) => {
	const {visible, setVisible, id} = props
	const [form] = Form.useForm()
	const {TextArea} = Input;
	const [express, setExpress] = useState([])
	useEffect(async () => {
		let data = await getExpress()
		// console.log('dddddd',data)
		setExpress(data.data)
	}, [])
	return (
		<div>
			<Modal
				visible={visible}
				onCancel={() => {
					setVisible(false)
				}}
				width={600}
				title="订单发送货"
				onOk={() => {
					form.validateFields().then(value => {
						console.log(value);
					})
				}}
			>
				{/* proform 中  ProFormRadio组件 */}
				<ProForm
					form={form}
					submitter={false}

				>
					<ProFormRadio.Group
						name="type"
						label="选择类型"
						//类型选择单选框值
						initialValue={'1'}
						options={[
							{
								label: '单规格',
								value: '1',
							},
							{
								label: '多规格',
								value: '2',
							},
							{
								label: '无需配送',
								value: '3',
							},
						]}
					/>
					<Form.Item shouldUpdate={(prevValues, curValues) => prevValues.type !== curValues.type}>
						{(forminstance) => {
							switch (forminstance.getFieldValue('type')) {
								case '1':
									return (
										<Form.Item >
											<ProFormRadio.Group
												name="send_type"
												initialValue={"hand"}
												label="发货类型:"
												options={[
													{
														label: '手动填写',
														value: 'hand',
													},
													{
														label: '电子面单打印',
														value: 'print',
													},
												]}
											/>
											<Form.Item
												shouldUpdate={(prevValues, curValues) => prevValues.send_type !== curValues.send_type}>
												{(forminstance) => {
													switch (forminstance.getFieldValue('send_type')) {
														case 'hand' :
															return (
																<div>
																	<ProFormSelect
																		params={express}
																		name="delivery_name"
																		placeholder="请选择快递公司"
																		label="快递公司:"
																		request={async () => {
																			return  express.map(item => {
																				return {label: item?.name, value: item?.name}
																			})
																		}}
																	/>
																	<ProFormText
																		name="delivery_id"
																		placeholder="请选择快递单号"
																		label="快递单号"
																	/>

																</div>
															)
															break;
														case 'print':
															return (
																<div>
																	<ProFormSelect
																		name="delivery_name"
																		placeholder="请选择快递公司"
																		label="快递公司:"
																		request={ async () => {
																			return express.map(item => {
																				return  {label:item.name , value: item.name}
																			})
																		}}
																	/>
																	<ProFormSelect
																		name="express_dump"
																		placeholder="请选择电子面单"
																		label="电子面单:"
																	/>
																	<ProFormText
																		name="sender_name"
																		placeholder="请输入寄件人姓名"
																		label="寄件人姓名:"
																	/>
																	<ProFormText
																		name="sender_phone"
																		placeholder="请输入寄件人电话"
																		label="寄件人电话:"
																	/>
																	<ProFormText
																		name="sender_address"
																		placeholder="请输入寄件人地址"
																		label="寄件人地址:"
																	/>
																</div>
															)
													}
												}}
											</Form.Item>
										</Form.Item>
									);
									break;
								case '2':
									return (
										<Form.Item>
											<ProFormSelect
												name=""
												label="送货人"
												valueEnum={{
													like: `魏鹏飞 (13541587562)`,
												}}
											/>
										</Form.Item>
									);
									break;
								case '3':
									return (
										<Form.Item>
											<span>分单发货:</span>
											<TextArea
												style={{marginTop: '15px'}}
												rows={4}
												name="remark"
												placeholder="备注"/>
										</Form.Item>
									);
									break;
							}
						}}
					</Form.Item>
				</ProForm>
			</Modal>
		</div>
	);
};
export default SendGoodsModal;
